package cvsexercise5;

public class ControlledRepetition {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		/* Write out a start message to the console */
		System.out.println("Exercise 5 - Controlled Repetition");
		
		/* Declare and initialize an 2x2 array (M x N) of integers
		 * with the values {10, 20}, {30, 40}
		 * NOTE: the array will be identical to the 2D array from Exercise 6
		 * NOTE: use an initializer list to create the array!
		 */
		int[][] my2DArray = {{10, 20}, {30, 40}};
		
		/* Use a for loop to write out the values of each row of the array
		 * NOTE: use the array's length property to determine the loop-continuation condition
		 * NOTE: you will need to use nested for loops to access each column of each row
		 */
		System.out.println("2D Array Rows:");
		
		for (int idxRow = 0; idxRow < my2DArray.length; idxRow++) {
			for (int idxCol = 0; idxCol < my2DArray[idxRow].length; idxCol++) {
				System.out.println("my2DArray[" + idxRow + "][" + idxCol + "] = " + my2DArray[idxRow][idxCol]);
			}
		}
		
		
		/* Use a for loop to write out the values of each column of the array
		 * NOTE: again, you will need to use nested for loops to access each row of each column
		 * NOTE: you will need to initially determine the total number of rows in order to determine
		 *       the length of each column
		 */
		System.out.println("2D Array Columns:");
		
		int numRows = my2DArray.length;
		for (int idxCol = 0; idxCol < numRows; idxCol++) {
			for (int idxRow = 0; idxRow < my2DArray[idxCol].length; idxRow++) {
				System.out.println("my2DArray[" + idxRow + "][" + idxCol + "] = " + my2DArray[idxRow][idxCol]);
			}
		}
		
		/* Write out a completed message to the console */
		System.out.println("Exercise 5 - Controlled Repetition");

	}

}
